package cn.hsa.xxx.bookOrder.dto;

import cn.hsa.xxx.bookOrder.entity.OrderDO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;


@Component
public class OrderDTOConverter {

    /**
     * Convert OrderDTO to OrderDO
     *
     * @param orderDTO
     * @return
     */
    public OrderDO convertToOrderDO(OrderDTO orderDTO) {
        if (orderDTO == null) {
            return null;
        }
        OrderDO orderDO = new OrderDO();

        //OrderDO.setId(OrderDTO.getId());
        //OrderDO.setName(OrderDTO.getName());
        //OrderDO.setSex(OrderDTO.getSex());
        //OrderDO.setAddr(OrderDTO.getAddr());

        //性能略差，但使用方便
        BeanUtils.copyProperties(orderDTO, orderDO);

        return orderDO;
    }

    /**
     * Convert OrderDO to OrderDTO
     *
     * @param orderDO
     * @return
     */
    public OrderDTO convertToOrderDTO(OrderDO orderDO) {
        if (orderDO == null) {
            return null;
        }

        OrderDTO orderDTO = new OrderDTO();

        //OrderDTO.setId(OrderDO.getId());
        //OrderDTO.setName(OrderDO.getName());
        //OrderDTO.setSex(OrderDO.getSex());
        //OrderDTO.setAddr(OrderDO.getAddr());

        //性能略差，但使用方便
        BeanUtils.copyProperties(orderDO, orderDTO);

        return orderDTO;
    }
}
